#!/bin/bash

echo " 开始部署Nginx HA测试Web应用..."

# 检查Python
if ! command -v python3 &> /dev/null; then
    echo " 请先安装Python3"
    exit 1
fi

# 卸载可能存在的冲突包
echo " 清理旧版本..."
pip3 uninstall -y flask werkzeug jinja2 2>/dev/null || true

# 安装兼容版本依赖
echo "安装兼容版本依赖..."
pip3 install flask==1.1.4 werkzeug==1.0.1 jinja2==2.11.3 psutil==5.9.5

# 检查安装结果
if python3 -c "import flask, psutil; print('依赖安装成功')" &>/dev/null; then
    echo "所有依赖安装成功!"
else
    echo "依赖安装失败，尝试替代方案..."
    # 备用方案：使用系统自带的flask
    yum install -y python3-flask || apt-get install -y python3-flask
fi

echo "部署完成！"
echo ""
echo "启动命令:"
echo "   python3 app.py"
echo ""
echo "访问地址:"
echo "   主页: http://localhost:5000"
echo "   健康检查: http://localhost:5000/health"
echo "   系统信息: http://localhost:5000/api/system"
